﻿using UnityEngine;
using System.Collections;

public class FX_localrotate_loop : MonoBehaviour {

	public bool loop = false;
	public bool bLocalRot = false;
	
	public Vector3 vRotationValue = new Vector3 (0, 0, 0);
	
	public float duration = 1.0f;
	
	Quaternion vOriginalRotation;
	
	float timer = 0;
	
	[SerializeField]
	AnimationCurve curveX;
	[SerializeField]
	AnimationCurve curveY;
	[SerializeField]
	AnimationCurve curveZ;
	
	void Start(){
		vOriginalRotation = transform.rotation;
	}
	void Update ()
	{
		
		Vector3 rotation;
		rotation.x = curveX.Evaluate(timer)* vRotationValue.x;
		rotation.y = curveY.Evaluate(timer)* vRotationValue.y;
		rotation.z = curveZ.Evaluate(timer)* vRotationValue.z;
		
		if (bLocalRot) {
			transform.localRotation = Quaternion.Euler (rotation);
		} else {
			transform.localRotation = Quaternion.Euler (rotation)* vOriginalRotation;
		}
		
		timer += Time.deltaTime/duration;

		if (loop) {
						if (timer >= 1.0f) {
								timer = 0f;
						}
				}

	}
}
